package com.example.PolimiAssistant.common;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.Wsdl2Code.WebServices.PolimiAssistant.CourseExam;
import com.example.PolimiAssistant.R;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Vlado on 30.06.2014.
 */
public class ExamCallAdapter extends ArrayAdapter<CourseExam> {
    int resource;
    String response;
    Context context;

    public ExamCallAdapter(Context context, int resource, List<CourseExam> items) {
        super(context, resource, items);
        this.resource=resource;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        LinearLayout examView;
        CourseExam exam = getItem(position);

        //Inflate the view
        if(convertView==null)
        {
            examView = new LinearLayout(getContext());
            String inflater = Context.LAYOUT_INFLATER_SERVICE;
            LayoutInflater vi;
            vi = (LayoutInflater)getContext().getSystemService(inflater);
            vi.inflate(resource, examView, true);
        }
        else
        {
            examView = (LinearLayout) convertView;
        }
        //Get the text boxes from the classroom_list_item.xml file
        TextView cDate =(TextView)examView.findViewById(R.id.exam_call_item_date);
        TextView cStartDate =(TextView)examView.findViewById(R.id.exam_call_item_start_reg);
        TextView cStopDate =(TextView)examView.findViewById(R.id.exam_call_item_stop_reg);
        TextView cClassroom =(TextView)examView.findViewById(R.id.exam_call_item_classroom);
        TextView calreadyReg =(TextView)examView.findViewById(R.id.exam_call_item_already_reg);
        TextView cNotifSet =(TextView)examView.findViewById(R.id.exam_call_item_notif);

        cDate.setText(exam.exam_datetime_str);
        cStartDate.setText(exam.strat_reg_date_str);
        cStopDate.setText(exam.stop_reg_date_str);

        cClassroom.setText(String.valueOf(exam.classroom_nameField));
        String a = exam.already_registered ? "Yes" : "No";
        calreadyReg.setText(a);

        a = exam.notification_set ? "Yes" : "No";
        cNotifSet.setText(a);

        return examView;
    }
}
